package com.zyplayer.vertx.spring.boot.controller;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import io.vertx.core.MultiMap;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;

@Component
public class IndexController {

	private static final Logger logger = LoggerFactory.getLogger(IndexController.class);

	@Autowired
	private Router router;

	@PostConstruct
	public void deploy() {
		logger.info("IndexController deploy...");
		this.router.get("/vertx/index").handler(this::get);
	}

	private void get(RoutingContext routingContext) {
		MultiMap params = routingContext.request().params();
		String uri = routingContext.request().uri();
		logger.info("url:{} params: {}", uri, params.toString());
		routingContext.response().end(params.toString());
	}

}
